.class public Lcom/xiaomi/common/Network;
.super Ljava/lang/Object;
.source "Network.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/xiaomi/common/Network$DownloadTask;,
        Lcom/xiaomi/common/Network$PostDownloadHandler;
    }
.end annotation


# static fields
.field private static final LogTag:Ljava/lang/String; = "com.xiaomi.common.Network"

.field private static final SERVER_HOST:Ljava/lang/String; = "http://sj.xiaomi.com"

.field public static final UserAgent_PC_Chrome:Ljava/lang/String; = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.464.0 Safari/534.3"

.field public static final UserAgent_PC_Chrome_6_0_464_0:Ljava/lang/String; = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.464.0 Safari/534.3"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 28
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static beginDownloadFile(Ljava/lang/String;Ljava/io/OutputStream;Lcom/xiaomi/common/Network$PostDownloadHandler;)V
    .locals 2
    .parameter "url"
    .parameter "output"
    .parameter "handler"

    .prologue
    .line 164
    new-instance v0, Lcom/xiaomi/common/Network$DownloadTask;

    invoke-direct {v0, p0, p1, p2}, Lcom/xiaomi/common/Network$DownloadTask;-><init>(Ljava/lang/String;Ljava/io/OutputStream;Lcom/xiaomi/common/Network$PostDownloadHandler;)V

    .line 165
    .local v0, task:Lcom/xiaomi/common/Network$DownloadTask;
    const/4 v1, 0x0

    new-array v1, v1, [Ljava/lang/Void;

    invoke-virtual {v0, v1}, Lcom/xiaomi/common/Network$DownloadTask;->execute([Ljava/lang/Object;)Landroid/os/AsyncTask;

    .line 166
    return-void
.end method

.method public static doHttpPost(Ljava/lang/String;Ljava/util/List;)Ljava/lang/String;
    .locals 10
    .parameter "url"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/util/List",
            "<",
            "Lorg/apache/http/NameValuePair;",
            ">;)",
            "Ljava/lang/String;"
        }
    .end annotation

    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 96
    .local p1, nameValuePairs:Ljava/util/List;,"Ljava/util/List<Lorg/apache/http/NameValuePair;>;"
    invoke-static {p0}, Lcom/xiaomi/common/Strings;->isNullOrEmpty(Ljava/lang/String;)Z

    move-result v7

    if-eqz v7, :cond_0

    .line 97
    new-instance v7, Ljava/lang/IllegalArgumentException;

    const-string v8, "url"

    invoke-direct {v7, v8}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw v7

    .line 99
    :cond_0
    new-instance v1, Lorg/apache/http/params/BasicHttpParams;

    invoke-direct {v1}, Lorg/apache/http/params/BasicHttpParams;-><init>()V

    .line 100
    .local v1, httpParameters:Lorg/apache/http/params/BasicHttpParams;
    const/16 v7, 0x1388

    invoke-static {v1, v7}, Lorg/apache/http/params/HttpConnectionParams;->setConnectionTimeout(Lorg/apache/http/params/HttpParams;I)V

    .line 102
    new-instance v2, Lorg/apache/http/impl/client/DefaultHttpClient;

    invoke-direct {v2, v1}, Lorg/apache/http/impl/client/DefaultHttpClient;-><init>(Lorg/apache/http/params/HttpParams;)V

    .line 103
    .local v2, httpclient:Lorg/apache/http/client/HttpClient;
    new-instance v3, Lorg/apache/http/client/methods/HttpPost;

    invoke-direct {v3, p0}, Lorg/apache/http/client/methods/HttpPost;-><init>(Ljava/lang/String;)V

    .line 105
    .local v3, httppost:Lorg/apache/http/client/methods/HttpPost;
    if-eqz p1, :cond_1

    invoke-interface {p1}, Ljava/util/List;->size()I

    move-result v7

    if-eqz v7, :cond_1

    .line 106
    new-instance v7, Lorg/apache/http/client/entity/UrlEncodedFormEntity;

    const-string v8, "UTF-8"

    invoke-direct {v7, p1, v8}, Lorg/apache/http/client/entity/UrlEncodedFormEntity;-><init>(Ljava/util/List;Ljava/lang/String;)V

    invoke-virtual {v3, v7}, Lorg/apache/http/client/methods/HttpPost;->setEntity(Lorg/apache/http/HttpEntity;)V

    .line 108
    :cond_1
    invoke-interface {v2, v3}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v4

    .line 109
    .local v4, response:Lorg/apache/http/HttpResponse;
    invoke-interface {v4}, Lorg/apache/http/HttpResponse;->getStatusLine()Lorg/apache/http/StatusLine;

    move-result-object v7

    invoke-interface {v7}, Lorg/apache/http/StatusLine;->getStatusCode()I

    move-result v6

    .line 110
    .local v6, statusCode:I
    const-string v7, "com.xiaomi.common.Network"

    new-instance v8, Ljava/lang/StringBuilder;

    const-string v9, "Http POST Response Code: "

    invoke-direct {v8, v9}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v8, v6}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    invoke-static {v7, v8}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 111
    const/16 v7, 0xc8

    if-lt v6, v7, :cond_3

    const/16 v7, 0x12c

    if-ge v6, v7, :cond_3

    .line 112
    invoke-interface {v4}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v0

    .line 113
    .local v0, body:Lorg/apache/http/HttpEntity;
    if-eqz v0, :cond_2

    .line 114
    invoke-static {v0}, Lorg/apache/http/util/EntityUtils;->toString(Lorg/apache/http/HttpEntity;)Ljava/lang/String;

    move-result-object v5

    .line 116
    .local v5, result:Ljava/lang/String;
    if-eqz v5, :cond_2

    move-object v7, v5

    .line 123
    .end local v0           #body:Lorg/apache/http/HttpEntity;
    .end local v5           #result:Ljava/lang/String;
    :goto_0
    return-object v7

    .line 120
    .restart local v0       #body:Lorg/apache/http/HttpEntity;
    :cond_2
    const-string v7, ""

    goto :goto_0

    .line 123
    .end local v0           #body:Lorg/apache/http/HttpEntity;
    :cond_3
    const/4 v7, 0x0

    goto :goto_0
.end method

.method public static downloadFile(Ljava/lang/String;Ljava/io/OutputStream;)Z
    .locals 7
    .parameter "urlStr"
    .parameter "output"

    .prologue
    const/4 v6, 0x0

    .line 176
    :try_start_0
    new-instance v4, Ljava/net/URL;

    invoke-direct {v4, p0}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    .line 177
    .local v4, url:Ljava/net/URL;
    invoke-virtual {v4}, Ljava/net/URL;->openStream()Ljava/io/InputStream;

    move-result-object v3

    .line 179
    .local v3, input:Ljava/io/InputStream;
    const/16 v5, 0x400

    new-array v0, v5, [B

    .line 182
    .local v0, buffer:[B
    :goto_0
    invoke-virtual {v3, v0}, Ljava/io/InputStream;->read([B)I

    move-result v1

    .local v1, count:I
    if-gtz v1, :cond_0

    .line 186
    invoke-virtual {v3}, Ljava/io/InputStream;->close()V

    .line 187
    invoke-virtual {p1}, Ljava/io/OutputStream;->close()V

    .line 188
    const/4 v5, 0x1

    .line 193
    .end local v0           #buffer:[B
    .end local v1           #count:I
    .end local v3           #input:Ljava/io/InputStream;
    .end local v4           #url:Ljava/net/URL;
    :goto_1
    return v5

    .line 183
    .restart local v0       #buffer:[B
    .restart local v1       #count:I
    .restart local v3       #input:Ljava/io/InputStream;
    .restart local v4       #url:Ljava/net/URL;
    :cond_0
    const/4 v5, 0x0

    invoke-virtual {p1, v0, v5, v1}, Ljava/io/OutputStream;->write([BII)V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 189
    .end local v0           #buffer:[B
    .end local v1           #count:I
    .end local v3           #input:Ljava/io/InputStream;
    .end local v4           #url:Ljava/net/URL;
    :catch_0
    move-exception v5

    move-object v2, v5

    .line 190
    .local v2, e:Ljava/io/IOException;
    invoke-virtual {v2}, Ljava/io/IOException;->printStackTrace()V

    move v5, v6

    .line 193
    goto :goto_1
.end method

.method public static downloadXml(Landroid/content/Context;Ljava/net/URL;)Ljava/lang/String;
    .locals 3
    .parameter "context"
    .parameter "url"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 40
    const/4 v0, 0x0

    const/4 v1, 0x0

    const-string v2, "UTF-8"

    invoke-static {p0, p1, v0, v1, v2}, Lcom/xiaomi/common/Network;->downloadXml(Landroid/content/Context;Ljava/net/URL;ZLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public static downloadXml(Landroid/content/Context;Ljava/net/URL;ZLjava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .parameter "context"
    .parameter "url"
    .parameter "noEncryptUrl"
    .parameter "userAgent"
    .parameter "encoding"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 45
    if-nez p0, :cond_0

    .line 46
    new-instance p0, Ljava/lang/IllegalArgumentException;

    .end local p0
    const-string p1, "context"

    .end local p1
    invoke-direct {p0, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw p0

    .line 47
    .restart local p0
    .restart local p1
    :cond_0
    if-nez p1, :cond_1

    .line 48
    new-instance p0, Ljava/lang/IllegalArgumentException;

    .end local p0
    const-string p1, "url"

    .end local p1
    invoke-direct {p0, p1}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw p0

    .line 50
    .restart local p0
    .restart local p1
    :cond_1
    move-object p0, p1

    .line 51
    .local p0, newUrl:Ljava/net/URL;
    if-nez p2, :cond_2

    .line 52
    new-instance p0, Ljava/net/URL;

    .end local p0           #newUrl:Ljava/net/URL;
    invoke-virtual {p1}, Ljava/net/URL;->toString()Ljava/lang/String;

    move-result-object p1

    .end local p1
    invoke-static {p1}, Lcom/xiaomi/common/Network;->encryptURL(Ljava/lang/String;)Ljava/lang/String;

    move-result-object p1

    invoke-direct {p0, p1}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    .line 54
    .restart local p0       #newUrl:Ljava/net/URL;
    :cond_2
    const/4 p1, 0x0

    .line 57
    .local p1, responseStream:Ljava/io/InputStream;
    :try_start_0
    invoke-virtual {p0}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;

    move-result-object p0

    .end local p0           #newUrl:Ljava/net/URL;
    check-cast p0, Ljava/net/HttpURLConnection;

    .line 58
    .local p0, conn:Ljava/net/HttpURLConnection;
    const/16 p2, 0x1388

    invoke-virtual {p0, p2}, Ljava/net/HttpURLConnection;->setConnectTimeout(I)V

    .line 59
    .end local p2
    const/16 p2, 0x3a98

    invoke-virtual {p0, p2}, Ljava/net/HttpURLConnection;->setReadTimeout(I)V

    .line 60
    invoke-static {p3}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result p2

    if-nez p2, :cond_3

    .line 61
    const-string p2, "User-agent"

    invoke-virtual {p0, p2, p3}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 63
    :cond_3
    invoke-virtual {p0}, Ljava/net/HttpURLConnection;->getInputStream()Ljava/io/InputStream;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_1

    move-result-object p2

    .line 64
    .end local p1           #responseStream:Ljava/io/InputStream;
    .local p2, responseStream:Ljava/io/InputStream;
    :try_start_1
    new-instance p3, Ljava/lang/StringBuilder;

    .end local p3
    const/16 p0, 0x400

    invoke-direct {p3, p0}, Ljava/lang/StringBuilder;-><init>(I)V

    .line 65
    .end local p0           #conn:Ljava/net/HttpURLConnection;
    .local p3, sbReponse:Ljava/lang/StringBuilder;
    new-instance p1, Ljava/io/BufferedReader;

    new-instance p0, Ljava/io/InputStreamReader;

    invoke-direct {p0, p2, p4}, Ljava/io/InputStreamReader;-><init>(Ljava/io/InputStream;Ljava/lang/String;)V

    invoke-direct {p1, p0}, Ljava/io/BufferedReader;-><init>(Ljava/io/Reader;)V

    .line 67
    .local p1, reader:Ljava/io/BufferedReader;
    :goto_0
    invoke-virtual {p1}, Ljava/io/BufferedReader;->readLine()Ljava/lang/String;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    move-result-object p0

    .local p0, line:Ljava/lang/String;
    if-nez p0, :cond_5

    .line 72
    if-eqz p2, :cond_4

    .line 74
    :try_start_2
    invoke-virtual {p2}, Ljava/io/InputStream;->close()V
    :try_end_2
    .catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_1

    .line 81
    .end local p0           #line:Ljava/lang/String;
    .end local p1           #reader:Ljava/io/BufferedReader;
    .end local p2           #responseStream:Ljava/io/InputStream;
    .end local p4
    :cond_4
    :goto_1
    invoke-virtual {p3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    .line 82
    .local p0, responseXml:Ljava/lang/String;
    return-object p0

    .line 68
    .local p0, line:Ljava/lang/String;
    .restart local p1       #reader:Ljava/io/BufferedReader;
    .restart local p2       #responseStream:Ljava/io/InputStream;
    .restart local p4
    :cond_5
    :try_start_3
    invoke-virtual {p3, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    .line 69
    const-string p0, "\r\n"

    .end local p0           #line:Ljava/lang/String;
    invoke-virtual {p3, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_0

    .line 71
    .end local p1           #reader:Ljava/io/BufferedReader;
    .end local p3           #sbReponse:Ljava/lang/StringBuilder;
    :catchall_0
    move-exception p0

    move-object p1, p0

    move-object p0, p2

    .line 72
    .end local p2           #responseStream:Ljava/io/InputStream;
    .local p0, responseStream:Ljava/io/InputStream;
    :goto_2
    if-eqz p0, :cond_6

    .line 74
    :try_start_4
    invoke-virtual {p0}, Ljava/io/InputStream;->close()V
    :try_end_4
    .catch Ljava/io/IOException; {:try_start_4 .. :try_end_4} :catch_0

    .line 79
    .end local p0           #responseStream:Ljava/io/InputStream;
    .end local p4
    :cond_6
    :goto_3
    throw p1

    .line 75
    .restart local p0       #responseStream:Ljava/io/InputStream;
    .restart local p4
    :catch_0
    move-exception p0

    .line 76
    .local p0, e:Ljava/io/IOException;
    const-string p2, "com.xiaomi.common.Network"

    new-instance p3, Ljava/lang/StringBuilder;

    const-string p4, "Failed to close responseStream"

    .end local p4
    invoke-direct {p3, p4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0}, Ljava/io/IOException;->toString()Ljava/lang/String;

    move-result-object p0

    .end local p0           #e:Ljava/io/IOException;
    invoke-virtual {p3, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object p0

    invoke-virtual {p0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    invoke-static {p2, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_3

    .line 75
    .local p0, line:Ljava/lang/String;
    .restart local p1       #reader:Ljava/io/BufferedReader;
    .restart local p2       #responseStream:Ljava/io/InputStream;
    .restart local p3       #sbReponse:Ljava/lang/StringBuilder;
    .restart local p4
    :catch_1
    move-exception p0

    .line 76
    .local p0, e:Ljava/io/IOException;
    const-string p1, "com.xiaomi.common.Network"

    .end local p1           #reader:Ljava/io/BufferedReader;
    new-instance p2, Ljava/lang/StringBuilder;

    .end local p2           #responseStream:Ljava/io/InputStream;
    const-string p4, "Failed to close responseStream"

    .end local p4
    invoke-direct {p2, p4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0}, Ljava/io/IOException;->toString()Ljava/lang/String;

    move-result-object p0

    .end local p0           #e:Ljava/io/IOException;
    invoke-virtual {p2, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object p0

    invoke-virtual {p0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p0

    invoke-static {p1, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_1

    .line 71
    .local p1, responseStream:Ljava/io/InputStream;
    .local p3, userAgent:Ljava/lang/String;
    .restart local p4
    :catchall_1
    move-exception p0

    move-object v0, p0

    move-object p0, p1

    .end local p1           #responseStream:Ljava/io/InputStream;
    .local p0, responseStream:Ljava/io/InputStream;
    move-object p1, v0

    goto :goto_2
.end method

.method public static encryptURL(Ljava/lang/String;)Ljava/lang/String;
    .locals 5
    .parameter "strUrl"

    .prologue
    const/4 v4, 0x1

    const/4 v3, 0x0

    .line 145
    invoke-static {p0}, Lcom/xiaomi/common/Strings;->isNullOrEmpty(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_0

    .line 146
    new-instance v1, Ljava/lang/String;

    invoke-direct {v1}, Ljava/lang/String;-><init>()V

    .line 147
    const-string v1, "%sbe988a6134bc8254465424e5a70ef037"

    new-array v2, v4, [Ljava/lang/Object;

    aput-object p0, v2, v3

    invoke-static {v1, v2}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v0

    .line 148
    .local v0, strTemp:Ljava/lang/String;
    const-string v1, "%s&key=%s"

    const/4 v2, 0x2

    new-array v2, v2, [Ljava/lang/Object;

    aput-object p0, v2, v3

    invoke-static {v0}, Lcom/xiaomi/common/MD5;->MD5_32(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v3

    aput-object v3, v2, v4

    invoke-static {v1, v2}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    .line 150
    .end local v0           #strTemp:Ljava/lang/String;
    :goto_0
    return-object v1

    :cond_0
    const/4 v1, 0x0

    goto :goto_0
.end method

.method public static getFeedbackUrl(Landroid/content/Context;)Ljava/lang/String;
    .locals 4
    .parameter "context"

    .prologue
    .line 134
    const-string v0, "%1$s/%2$s?%3$s"

    const/4 v1, 0x3

    new-array v1, v1, [Ljava/lang/Object;

    const/4 v2, 0x0

    .line 135
    const-string v3, "http://sj.xiaomi.com"

    aput-object v3, v1, v2

    const/4 v2, 0x1

    .line 136
    const-string v3, "miniphp/ajax.php"

    aput-object v3, v1, v2

    const/4 v2, 0x2

    .line 137
    invoke-static {p0}, Lcom/xiaomi/common/UserInfo;->getUserIdQueryString(Landroid/content/Context;)Ljava/lang/String;

    move-result-object v3

    aput-object v3, v1, v2

    .line 133
    invoke-static {v0, v1}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method
